package com.fun.feifun.handler;

import cn.dev33.satoken.exception.NotLoginException;
import com.fun.feifun.base.result.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author wukefei
 * @date $ $
 */
@ControllerAdvice
public class GlobalExceptionHandler {
    private static String CLIENT_ABORT_EXCEPTION_PACKAGE_NAME = "org.apache.catalina.connector.ClientAbortException";

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result handleException(Exception e) {
        //接口限流异常处理
        if (e != null && CLIENT_ABORT_EXCEPTION_PACKAGE_NAME.equals(e.getClass().getName())) {
            return null;
        }
        e.printStackTrace();
        if(e instanceof NotLoginException){
            return Result.err(e.getMessage());
        }else {
            return Result.err(e.getMessage());
        }
    }
}
